const root = require("./tree");

var backend = (root) => {
    let res = [];
    let offInorderTrabversal = (node) => {
        if(node){
            offInorderTrabversal(node.left);
            offInorderTrabversal(node.right);
            res.push(node.value);
        }
    };
    offInorderTrabversal(root);
    return res;
};

//前序遍历 根左右   unshift -> 右左根 -> 左右根
//后序遍历 左右根
var backend2 = (root) => {
    let res = [];
    let stack = [];
    if(root) stack.push(root);
    while(stack.length){
        let node = stack.pop();
        res.unshift(node.value);
        if(node.left) stack.push(node.left);
        if(node.right) stack.push(node.right);
    }
    return res;
};
console.log(backend(root));
console.log(backend2(root));